#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random,time,queue
from multiprocessing.managers import BaseManager

class QueueManager(BaseManager):
    pass
QueueManager.register('get_task_queue')
QueueManager.register('get_result_queue')
print('Connect to server 111.111.111.10')
m = QueueManager(address=('111.111.111.10',5300),authkey = b'abc')
m.connect()
task = m.get_task_queue()
result = m.get_result_queue()
for value in range(10):
    try:
        n = task.get(timeout=1)
        print('run task %d * %d---' %(n,n))
        r = '%d * %d = %d'%(n,n,n*n)
        result.put(r)
    except Queue.Empty:
        print('task queue is empty')
print('worker exit')
